<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>

		<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
	</head>
	<body>
		<div id="app">
			{{num}}
			<br />
			<input type="text" v-model="num" />
			<br />
			{{message}}
			<br/>
			{{result}}
		</div>
		
		<script>
			var app = Vue.createApp({
				data() {
					return {
						"message": "Hello Vue!",
						"num":10,
						"result":0
					}
				},
				// 方法
				methods:{

				},
				// 数据的监听
				watch:{
					num(newVal,oldVal){
						console.log("旧的值"+oldVal)
						console.log("新的值"+newVal)
						this.message = "监听到num数据改变了，旧的值"+oldVal+"新的值"+newVal
						// this.sleep(2000)
						// // this.result = newVal * newVal;
						// this.result = Math.sqrt(parseInt(newVal))
						// console.log(this.result);
						
						// 1. 新建一个Worker线程
						var worker = new Worker("longtask.js")
						
						// 2. 注册worker发回数据的处理
						worker.onmessage = (event)=>this.result=event.data;
						
						// 3. 向worker发送数据
						worker.postMessage(newVal)
						
						
						
						
						
					}
				}
				
			});
			var vm = app.mount("#app")
		</script>



	</body>
</html>